package com.xysq.adapter;
/*
* @author Huangdongkai
*/

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockcent.model.CouponBO;
import com.rockcent.model.CouponModel;
import com.xysq.lemon.R;
import com.xysq.util.PropertiesUtil;

import butterknife.InjectView;

public class CategoryAdapter extends BaseDataAdapter<CouponBO> {

    public CategoryAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_category_list, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CouponModel coupon = itemList.get(position);
        holder.titleTxt.setText(coupon.getName());
        if (!coupon.getPicUrl().isEmpty()) {
            String logoUrl = coupon.getPicUrl().split(";")[0];
            logoUrl = PropertiesUtil.getImageServer() + logoUrl;
            imageLoader.displayImage(logoUrl, holder.picImg);
        }
        return convertView;
    }

    static class ViewHolder extends BaseViewHolder {
        @InjectView(R.id.img_pic)
        ImageView picImg;
        @InjectView(R.id.txt_title)
        TextView titleTxt;

        public ViewHolder(View view) {
            super(view);
        }
    }
}
